Creating a Circle

This example demonstrates how to create a circle, set its properties, and then fly to it. This example uses the ICreator81 (CreatePosition, CreateColor, CreateCircle, CreateMessage), INavigate81 (FlyTo), IPosition81 (Copy, Pitch), IColor81, ITerrainRegularPolygon81 (Radius, Message), IFillStyle81 (Color) and ITerraExplorerMessage81 (ID) properties and methods.

 

function CreateCircle()

      {

      try

      {

      //

      // B.  Create position for circle

      //

      // B1. Set position input parameters (San Francisco shore)

      var dXCoord = -122.49460;

      var dYCoord = 37.78816;

      var dAltitude = 100.0;

      var eAltitudeTypeCode = 0; //AltitudeTypeCode.ATC_TERRAIN_RELATIVE;

      var dYaw = 0.0;

      var dPitch = 0.0;

      var dRoll = 0.0;

      var dDistance = 5000;

 

      // B2. Create Position

      var cPos = sgworld.Creator.CreatePosition(dXCoord, dYCoord, dAltitude, eAltitudeTypeCode, dYaw, dPitch, dRoll, dDistance);

 

      //

      // C. create FillColor for circle

      //

      {

      // C1. Set fill color input params - RGB and Alpha

      var nRed = 0;

      var nGreen = 255;

      var nBlue = 0;

      var nAlpha = 0x7F; // 50% opacity

 

      // C2. Create fill color

      var cFillColor = sgworld.Creator.CreateColor(nRed, nGreen, nBlue, nAlpha);

      }

 

      //

      // D. Create circle using created position and fill color (for line color use Abgr uint value)

      //

      {

      // D1. Set circle input params

      var nLineColor = 0xFFFF0000;   // Abgr value - Solid blue

      var dCircleRadius = 200;     // in meters

 

      // D2. Create circle

      var cCircle = sgworld.Creator.CreateCircle(cPos, dCircleRadius, nLineColor, cFillColor, "", "Circle");

      }

 

      //

      // E. Get and change circle properties

      //

      {

      // E1. Get & Set circle radius

      var dNewCircleRadius = 300;

      var dCurrentCircleRadius = cCircle.Radius; // Get circle radius

      cCircle.Radius = dNewCircleRadius;            // Set new circle radius

 

      // E2. Get fill style and change its properties

      var nRGB_Red = 0xFF0000;  // uing Rgb - Red color

      var dAlpha = 0.2;       // 81% transparent

      var cFillStyle = cCircle.FillStyle;

      cFillStyle.Color.FromRGBColor(nRGB_Red);

      cFillStyle.Color.SetAlpha(dAlpha);

      }

 

      //

      // F. Add Message to created circle

      //

      {

      // F1. Set message input parameters

      var eTargetPosition = 5; //TargetPosition6.MC_POPUP;

      var tMessage = "Hello Circle";

      var eMsgType = 0; //MsgType.TYPE_TEXT;

      var bIsBringToFront = true;

 

      // F2. Create message and add to circle

      var cMessage = sgworld.Creator.CreateMessage(eTargetPosition, tMessage, eMsgType, bIsBringToFront);

      cCircle.Message.MessageID = cMessage.ID;

      }

 

      //

      // G. FlyTo created circle

      //

      {

      var cFlyToPos = cPos.Copy();

      cFlyToPos.Pitch = -89.0; // Set camera to look downward on circle

      sgworld.Navigate.FlyTo(cFlyToPos);

      }

      }

      catch (e)

      {

      alert("Unexpected error: " + e.description);

      }

      }